var app = new Vue({
    el: '#addschool',
    data() {
        return {
            mainimg: ""
        }
    },
    mounted: function () {
    },
    methods: {
    }
});

layui.use(['form', 'upload', 'element', 'layedit'], function () {
    let form = layui.form, layedit = layui.layedit;
    //创建一个题目编辑器
    let editIndex = layedit.build('newscontents', {
        tool: [
            'strong'
            , 'italic'
            , 'underline'
            , 'del'
            , '|'
            , 'link'
            , 'face'
            , 'image'
        ]
    });
    form.on('submit(demo1)', function (data) {
        if (data.field.name.length > 200) {
            layer.msg('学校名称过长', {
                time: 1000,
                icon: 2,
                offset: '150px'
            });
            return false;
        }
        var object = new Object();
        object["name"] = data.field.name;
        object["description"] = data.field.description;
        var jsonData = JSON.stringify(object);
        console.log(jsonData)
        console.log(123)
        $.ajax({
            url: basePath + "/school/insert",
            data: jsonData,
            contentType: "application/json;charset=UTF-8",
            type: "post",
            dataType: "json",
            beforeSend: function () {
                layer.load(1, {
                    content: '发布中...',
                    success: function (layero) {
                        layero.find('.layui-layer-content').css({
                            'padding-top': '39px',
                            'width': '60px'
                        });
                    }
                });
            },
            complete: function () {
                layer.closeAll('loading');
            },
            success: function (data) {
                if(data.status===200){
                    layer.msg("新增成功", {
                        time: 1000,
                        icon: 1,
                        offset: '100px'
                    }, function () {
                        window.location.reload();
                    });
                }else {
                    layer.msg(data.message, {
                        time: 1000,
                        icon: 2,
                        offset: '50px'
                    });
                }
            }, error: function () {
                layer.msg('发布失败', {
                    time: 1000,
                    icon: 2,
                    offset: '150px'
                });
            }
        });
        return false;
    });
});